*************************************************************************************************************************
****************************** EXTREMISM AND TERRORISM: REBEL GOALS AND TACTICS IN CIVIL WARS ***************************
******************************* RENANAH MILES JOYCE AND PAGE FORTNA *****************************************************
*********************************** PERSPECTIVES ON POLITICS [2024] *****************************************************
*************************************************************************************************************************

clear

cap ssc install estout
cap ssc install parmest
cap ssc install mimrgns
cap ssc install coefplot

use "ReplicationData.dta", replace																								

stset, clear

**********************************************************************************************************************
*********************** DATA PREP ************************************************************************************
**********************************************************************************************************************
																							
*** Recode missing 
replace ideology =. if ideology == -99 
replace identitystatus =. if identitystatus == -99

*** Create dummy for major identity status change goals
gen id_major = 1 if identitystatus == 2
replace id_major = 0 if identitystatus < 2

*** Create dummy for secession goals
gen secession = 1 if borders == 2 | borders == 1 & independence == 1
replace secession = 0 if borders == 0 | borders == 1 & independence == 0

*** Create dummy for pooled extremism variable
gen extreme = 1 if ideology == 1 | id_major == 1 | secession == 1
replace extreme = 0 if ideology != 1 & id_major != 1 & secession != 1

*** Create lagged variables
sort dyadid year
by dyadid: gen km_a_lag1 = L1.km_a
by dyadid: gen rebstrength_lag1 = L1.rebstrength
by dyadid: gen mobcap_lag1 = L1.mobcap
by dyadid: gen war_lag1 = L1.war

*** Round dv
replace km_a=round(km_a)  								

*** Label variables for analysis 																											
label var ideology "Transform system (ideology)"
label var secession "Secession"
label var id_major "Transform system (identity)"
label var xpolity_int_lag1 "Democracy"
label var finances_lag1 "Rebel financing"
label var rebstrength_lag1 "Rebel strength"
label var mobcap_lag1 "Popular support"
label var war_lag1 "Conflict intensity"
label var EPRethnic "Ethnic conflict"
label var mult_groups "Multiple groups"
label var coldwar "Cold War"
label var km_a "Terrorism fatalities"
label var tm_a "Terrorism attacks"
label var extreme "Extreme aim"
label var lnpop "ln(population)"							

*** Treat as panel data
xtset dyadid year 

*** Drop observations for analysis 
drop if year ==. /* drop conflicts and dyads that exit the data before 1970 */
drop if dyadid == 360 /* drop al-Qaeda-US dyad */
drop if dyadid == 643 /* drop Hezbollah-Israel dyad */
drop if in_ucdp != 1


** MI code
mi set flong
mi register imputed km_a extreme xpolity_int_lag1 rebstrength_lag1 mobcap_lag1 mult_groups war_lag1 EPRethnic finances_lag1 lnpop coldwar GTD2 GTD3 GTD4

mi impute chained (pmm, knn(5)) km_a xpolity_int_lag1 lnpop (logit) war_lag1 EPRethnic finances_lag1 (ologit) mobcap_lag1 rebstrength_lag1 = extreme mult_groups coldwar GTD2 GTD3 GTD4, add(50) augment

**********************************************************************************************************************
*********************** ROBUSTNESS TESTS: MULTIPLE IMPUTATION (TABLE A8) *********************************************		
**********************************************************************************************************************

*** Model 1 pooled conflicts 
mi estimate, cmdok post: zinb km_a i.extreme xpolity_int_lag1 rebstrength_lag1 mobcap_lag1 i.mult_groups i.war_lag1 i.EPRethnic ///
i.finances_lag1 lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4, inflate (i.extreme xpolity_int_lag1 rebstrength_lag1 mobcap_lag1 i.mult_groups ///
i.war_lag1 i.EPRethnic i.finances_lag1 lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_pooled_mi

estout zinb_pooled_mi using tableA8_pooled.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.extreme Extremeaim xpolity_int_lag1 Democracy rebstrength_lag1 Rebelstrength mobcap_lag1 Popularsupport 1.mult_groups ///
Multiplegroups 1.war_lag1 Conflictintensity 1.EPRethnic Ethnicconflict 1.finances_lag1 Rebelfinancing lnpop Population 1.coldwar ColdWar)

*** Model 2 government conflicts
mi estimate, cmdok post: zinb km_a i.ideology i.id_major xpolity_int_lag1 rebstrength_lag1 mobcap_lag1 i.mult_groups i.war_lag1 i.EPRethnic ///
i.finances_lag1 lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==1, inflate (i.ideology i.id_major xpolity_int_lag1 rebstrength_lag1 ///
mobcap_lag1 i.mult_groups i.war_lag1 i.EPRethnic i.finances_lag1 lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_gov_mi

estout zinb_gov_mi using tableA8_gov.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
varlabels (1.ideology Ideology 1.id_major Identity xpolity_int_lag1 Democracy rebstrength_lag1 Rebelstrength mobcap_lag1 Popularsupport ///
1.mult_groups Multiplegroups 1.war_lag1 Conflictintensity 1.EPRethnic Ethnicconflict 1.finances_lag1 Rebelfinancing lnpop Population 1.coldwar ColdWar)

*** Model 3 territory conflicts
mi estimate, cmdok post: zinb km_a i.secession xpolity_int_lag1 rebstrength_lag1 mobcap_lag1 i.mult_groups i.war_lag1 i.EPRethnic ///
i.finances_lag1 lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4 if govtInc==0, inflate (i.secession xpolity_int_lag1 rebstrength_lag1 mobcap_lag1 ///
i.mult_groups i.war_lag1 i.EPRethnic i.finances_lag1 lnpop i.coldwar i.GTD2 i.GTD3 i.GTD4) vce (cluster conflictid) nolog 
est sto zinb_ter_mi

estout zinb_ter_mi using tableA8_ter.txt, cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) varlabels (1.secession Secession ///
xpolity_int_lag1 Democracy rebstrength_lag1 Rebelstrength mobcap_lag1 Popularsupport 1.mult_groups Multiplegroups ///
1.war_lag1 Conflictintensity 1.EPRethnic Ethnicconflict 1.finances_lag1 Rebelfinancing lnpop Population 1.coldwar ColdWar)


clear

